// 个人办公-->通信录
Ext.onReady(function(){
    Ext.define('json_data',{
        extend: 'Ext.data.Model',
        fields: [
			 {name:'id',type:'string'},
			 {name:'name',type:'string'},
			 {name:'gender',type:'string'},
             {name:'phone',type:'string'},
             {name:'email',type:'string'},
             {name:'qq',type:'string'},
             {name:'state',type:'string'}
        ]
    });
    //创建数据源
    var store = Ext.create('Ext.data.Store', {
    	pageSize:20,
        model: 'json_data',
	    proxy: {
	        type: 'ajax',
	        url: '/employecontrol/employe_list/',
	        actionMethods:'post',
	        reader: {
	            type: 'json',
	            root: 'rows',
	            totalProperty: 'totalCount'
	        }
	    },
	    autoLoad: false
    });
    //多选
    var selModel = Ext.create('Ext.selection.CheckboxModel');
    //创建Grid
    var grid = Ext.create('Ext.grid.Panel',{
        store: store,
        //height: 500,
        //selModel:selModel,
        columnLines:true,
        columns: [
            Ext.create('Ext.grid.RowNumberer'),// 序列
			{text: "ID", width: 80, dataIndex: 'id', sortable: false,hidden : true},
            {text: "姓名", width: 80, dataIndex: 'name', sortable: false},
            {text: "性别", width: 40, dataIndex: 'gender', sortable: false,
                renderer:function(v){
            	if (v==1) 
                	return '男'
    			else
        			return '女'
            	}},
            {text: "手机", width: 120, dataIndex: 'phone', sortable: false},
            {text: "邮箱", width: 120, dataIndex: 'email', sortable: false},
            {text: "QQ", width: 120, dataIndex: 'qq', sortable: false},
            {text: "状态", width: 120, dataIndex: 'state', sortable: false,
                renderer:function(v){
            	if (v==1) 
                	return '入职'
            	if (v==2) 
            		return '转正'
        		if (v==3) 
        			return '离职'
    			if (v==4) 
    				return '全职'
				if (v==5) 
					return '兼职'
    			else
        			return '招聘'
            	}}
        ],
        // disableSelection: false,
        layout : 'fit',
        //frame:true,
        loadMask:true,
        region: 'north',
        //renderTo: 'address_book-grid',
        viewConfig: {
            stripeRows: true
        },
        dockedItems : [{
            xtype : 'pagingtoolbar',
            store : store,
            dock : 'bottom',
            displayInfo : true,
            //displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
            autoScroll:true 
        },{
        	dock:'top',
        	xtype:'toolbar',
        	items:[{
        		xtype: 'combobox',
        		labelWidth: 30,
        		width:130,
        		id:'company_combox_id',
            	name:'company',
               	fieldLabel: '校区',
               	emptyText: '请选择校区',
               	editable:false,
               	store: new Ext.data.Store({ 
                   	singleton : true, 
        	   	    proxy: {
        	   	        type: 'ajax',
        	   	        url: '/resourcecontrol/company_select_all/',
        	   	        actionMethods:'post',
        	   	        reader: {
        	   	            type: 'json'
        	   	        }
        	   	    },
                   fields:['id', 'cn_name'], 
                   autoLoad:true 
               	}), 
               	loadingText:'正在加载数据，请稍侯……', 
               	triggerAction:'all', 
               	valueField:'id', 
               	displayField:'cn_name'        		
        	},{
        		id:'name',
        		xtype:'textfield',
        		labelWidth: 30,
        		width:130,
        		fieldLabel:'姓名'
        	},{
        		xtype:'button',
        		text:'查询',
        		iconCls:'search', 
        		handler:function(){
	        		if(Ext.getCmp('company_combox_id').getValue()!=null){
	        			var params = { company_id:Ext.getCmp('company_combox_id').getValue() ,name: Ext.getCmp('name').getValue() };
	        		    Ext.apply(store.proxy.extraParams, params);
	        		    store.currentPage=1;
	        		    store.load();
	        		}else{
	        			Ext.Msg.alert('系统提示', '请选择校区!');
	        		}
        		}
        	}]
        }]
    });
    
    
	Ext.create('Ext.container.Viewport',{
		layout:'fit',
		renderTo: 'address_book-grid',
		items:[grid]
	});
	
    
});